<!DOCTYPE html>
<html>
    <head>
        <!-- 页面meta -->
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <title>传智健康</title>
        <meta name="description" content="传智健康">
        <meta name="keywords" content="传智健康">
        <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">
        <!-- 引入样式 -->
        <link rel="stylesheet" href="../plugins/elementui/index.css">
        <link rel="stylesheet" href="../plugins/font-awesome/css/font-awesome.min.css">
        <link rel="stylesheet" href="../css/style.css">
        <!-- 引入组件库 -->
        <script type="text/javascript" src="../js/jquery.min.js"></script>
        <script src="../js/vue.js"></script>
        <script src="../plugins/elementui/index.js"></script>
        <script src="../js/axios-0.18.0.js"></script>
        <style>
            .datatable {
                position: relative;
                box-sizing: border-box;
                -webkit-box-flex: 1;
                width: 100%;
                max-width: 100%;
                font-size: 14px;
                color: rgb(96, 98, 102);
                overflow: hidden;
                flex: 1 1 0%;
            }
            .datatable td, .datatable th {
                padding: 12px 0;
                min-width: 0;
                -webkit-box-sizing: border-box;
                box-sizing: border-box;
                text-overflow: ellipsis;
                vertical-align: middle;
                position: relative;
                text-align: left;
            }
        </style>
    </head>
    <body class="hold-transition">
        <div id="app">
            <div class="content-header">
                <h1>菜单管理<small>菜单组管理</small></h1>
                <el-breadcrumb separator-class="el-icon-arrow-right" class="breadcrumb">
                    <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
                    <el-breadcrumb-item>菜单管理</el-breadcrumb-item>
                    <el-breadcrumb-item>菜单组管理</el-breadcrumb-item>
                </el-breadcrumb>
            </div>
            <div class="app-container">
                <div class="box">
                    <div class="filter-container">
                        <el-input placeholder="菜单id/菜单名" v-model="pagination.queryString" style="width: 200px;" class="filter-item" @keyup.enter.native="handleFilter"></el-input>
                        <el-button @click="findPage()" class="dalfBut">查询</el-button>
                        <el-button type="primary" class="butT" @click="handleCreate()">新建</el-button>
                    </div>
                    <el-table size="small" current-row-key="id" :data="dataList" stripe highlight-current-row>
                        <el-table-column type="index" align="center" label="序号"></el-table-column>
                        <el-table-column prop="id" label="菜单id" align="center"></el-table-column>
                        <el-table-column prop="name" label="菜单名称" align="center"></el-table-column>
                        <el-table-column prop="keyword" label="linkUrl" align="center"></el-table-column>
                        <el-table-column prop="level" label="菜单级别" align="center"></el-table-column>
                        <el-table-column label="操作" align="center">
                            <template slot-scope="scope">
                                <el-button type="primary" size="mini" @click="handleUpdate(scope.row)">编辑</el-button>
                                <el-button size="mini" type="danger" @click="handleDelete(scope.row)">删除</el-button>
                            </template>
                        </el-table-column>
                    </el-table>
                    <div class="pagination-container">
                        <el-pagination
                            class="pagiantion"
                            @current-change="handleCurrentChange"
                            :current-page="pagination.currentPage"
                            :page-size="pagination.pageSize"
                            layout="total, prev, pager, next, jumper"
                            :total="pagination.total">
                        </el-pagination>
                    </div>
                    <!-- 新增标签弹层 -->
                    <div class="add-form">
                        <el-dialog title="新增权限" :visible.sync="dialogFormVisible">
                            <template>
                                <el-tabs v-model="activeName" type="card">
                                    <el-tab-pane label="权限基本信息" name="first">
                                        <el-form label-position="right" label-width="100px">
                                            <el-row>
                                                <el-col :span="12">
                                                    <el-form-item label="权限name">
                                                        <el-input v-model="formData.name"/>
                                                    </el-form-item>
                                                </el-col>
                                                <el-col :span="12">
                                                    <el-form-item label="权限keyword">
                                                        <el-input v-model="formData.keyword"/>
                                                    </el-form-item>
                                                </el-col>
                                            </el-row>
                                                <el-col :span="24">
                                                    <el-form-item label="权限描述">
                                                        <el-input v-model="formData.description" type="textarea"></el-input>
                                                    </el-form-item>
                                                </el-col>
                                            </el-row>
                                        </el-form>
                                    </el-tab-pane>
                                </el-tabs>
                            </template>
                            <div slot="footer" class="dialog-footer">
                                <el-button @click="dialogFormVisible = false">取消</el-button>
                                <el-button type="primary" @click="handleAdd()">确定</el-button>
                            </div>
                        </el-dialog>
                    </div>

                    <!-- 编辑标签弹层 -->
                    <div class="add-form">
                        <el-dialog title="新增权限" :visible.sync="dialogFormVisible4Edit">
                            <template>
                                <el-tabs v-model="activeName" type="card">
                                    <el-tab-pane label="权限基本信息" name="first">
                                        <el-form label-position="right" label-width="100px">
                                            <el-row>
                                                <el-col :span="12">
                                                    <el-form-item label="权限name">
                                                        <el-input v-model="formData.name"/>
                                                    </el-form-item>
                                                </el-col>
                                                <el-col :span="12">
                                                    <el-form-item label="权限keyword">
                                                        <el-input v-model="formData.keyword"/>
                                                    </el-form-item>
                                                </el-col>
                                            </el-row>
                                            <el-col :span="24">
                                                <el-form-item label="权限描述">
                                                    <el-input v-model="formData.description" type="textarea"></el-input>
                                                </el-form-item>
                                            </el-col>
                                            </el-row>
                                        </el-form>
                                    </el-tab-pane>
                                </el-tabs>
                            </template>
                            <div slot="footer" class="dialog-footer">
                                <el-button @click="dialogFormVisible = false">取消</el-button>
                                <el-button type="primary" @click="handleEdit()">确定</el-button>
                            </div>
                        </el-dialog>
                    </div>
                </div>
            </div>
        </div>
    </body>

    <script>
        var vue = new Vue({
            el: '#app',
            data:{
                activeName:'first',//添加/编辑窗口Tab标签名称
                pagination: {//分页相关属性
                    currentPage: 1,
                    pageSize:10,
                    total:100,
                    queryString:null,
                },
                dataList: [],//列表数据
                formData: {},//表单数据 新增检查组
                tableData:[],//新增和编辑表单中对应的检查项列表数据 检查项的全部数据
                checkgroupId:[],//新增和编辑表单中检查项对应的复选框，基于双向绑定可以进行回显和数据提交 检查项的全部id
                dialogFormVisible: false,//控制添加窗口显示/隐藏
                dialogFormVisible4Edit:false//控制编辑窗口显示/隐藏
            },
            created() {
                this.findPage();
            },
            methods: {
                //编辑
                handleEdit() {
                    //发送axios请求
                    axios.post('/permission/edit.do?',this.formData).then((resp)=>{
                        //如果返回是true
                        if(resp.data.flag){
                            //显示添加成功
                            this.$message({
                                message:resp.data.message,
                                type:'success'
                            })
                            //隐藏修改表单
                            //情空表单
                            this.dialogFormVisible4Edit=false;
                            this.formData={};
                            //显示分页信息
                            this.findPage();
                        }else{
                            //如果返回的是false
                            this.$message.error(resp.data.message);
                        }


                    })
                },
                //添加
                handleAdd () {
                    //直接发送axios请求
                    axios.post('/permission/add.do?',this.formData).then((resp)=>{
                        //根据返回true和false判断添加是否成功,无论如何都会重新分页
                        if(resp.data.flag){
                            this.$message({
                                message:resp.data.message,
                                type:'success'
                            })
                            //添加成功后,隐藏框,并且清空数据
                            this.dialogFormVisible=false;
                            this.formData={};
                        }else{
                            //添加失败
                            this.$message.error(resp.data.message);
                        }
                    }).finally(()=>{
                        this.findPage();
                    })
                },
                //分页查询
                findPage() {
                    //先拿到分页必须货到的数据，当前页,每页显示多少个,查询条件
                    //传递参数是目标对象的参数:这个model的参数
                    var param={
                        currentPage:this.pagination.currentPage,
                        pageSize:this.pagination.pageSize,
                        queryString:this.pagination.queryString
                    }
                    //发送ajax请求,然后赋值给model,让它自动显示
                    axios.post('/menu/findPage.do',param).then((resp)=>{
                        console.log(param);
                        this.dataList=resp.data.rows; //返回当前查到的列表
                        this.pagination.total=resp.data.total;  //返回分页的总数
                    })
                },
                // 重置表单
                resetForm() {
                    this.formData={};
                },
                // 弹出添加窗口
                handleCreate() {
                    //先重置数据
                    this.resetForm();
                    //显示添加窗口
                    this.dialogFormVisible=true;
                    //默认打开基本信息页
                    this.activeName='first';
                    //然后查询所有检查项的信息
                    axios('/checkitem/findAll.do').then((resp)=>{
                        //查询出来如果返回的是true
                        if(resp.data.flag){
                            //查询所有信息,赋值给tableData让它自己遍历
                            this.tableData=resp.data.data;
                        }else{
                            //查询检查项失败
                            this.$message.error(resp.data.message);
                        }

                    })
                },
                // 弹出编辑窗口
                handleUpdate(row) {
                    this.dialogFormVisible4Edit=true;
                    //默认打开基本信息页
                    this.activeName='first';
                    //根据id,发送axios请求,根据id获取当前组的数据,当前组回显数据是用formData
                    axios.post('/permission/findFormDataById.do?id='+row.id).then((resp)=>{
                        if(resp.data.flag){
                            this.formData=resp.data.data;
                        }else{
                            //如果编辑框数据查不到
                            this.$message.error(resp.data.message);
                        }

                    });
                },
                //切换页码
                handleCurrentChange(currentPage) {
                    this.pagination.currentPage=currentPage;
                    this.findPage();
                },
                // 删除
                handleDelete(row) {

                    this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
                        confirmButtonText: '确定',
                        cancelButtonText: '取消',
                        type: 'warning'
                    }).then(() => {

                        axios.get("/menu/deleteMenuById.do?id=" + row.id).then((res) => {

                            // console.log(res.data);

                            if(res.data.flag){
                                //删除成功
                                this.$message({
                                    message: res.data.message,
                                    type: 'success'
                                })
                            }else{
                                this.$message.error(res.data.message);
                            }

                            this.findPage();

                        }).catch((r) => {
                            this.showMessage(r);
                        });
                        // this.$message({
                        //     type: 'success',
                        //     message: '删除成功!'
                        // });
                    }).catch(() => {
                        this.$message({
                            type: 'info',
                            message: '已取消删除'
                        });
                    });

                }
            }
        })
    </script>
</html>
